import axios from "axios";
import { host } from "../env";
const handleUrl = url => {
	if(url.startsWith("http") || url.startsWith("https")) {
		return url;
	}else {
		console.log(host + url);
		return host + url;
	}
};
class Net {
	constructor() {
		axios.defaults.withCredentials = false;
	}
	get(url) {
		return new Promise((resolve, reject) => {
			axios.get(handleUrl(url)).then(res => {
				if(res.data && res.data.code === 1) {
					resolve(res.data);
				}else {
					resolve(null);
				}
			}).catch(err => {
				reject(err);
			});
		});
	}
}

export default new Net();